﻿using Abp.AspNetCore;
using Abp.EntityFrameworkCore;
using Abp.EntityFrameworkCore.Configuration;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Batman.Cms.Core;
using Batman.Cms.Hosting;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Batman.Cms
{
    [DependsOn(typeof(AbpEntityFrameworkCoreModule), typeof(AbpAspNetCoreModule))]
    public class CmsModule : AbpModule
    {
        public override void PreInitialize()
        {
            Configuration.Modules.AbpEfCore().AddDbContext<CmsDbContext>(options =>
            {
                if (options.ExistingConnection != null)
                {
                    options.DbContextOptions.UseSqlServer(options.ExistingConnection);
                }
                else
                {
                    options.DbContextOptions.UseSqlServer("Data Source=115.159.146.180;Initial Catalog=batman.cms.dev;user id=sa;password=shake@123");
                }
            });

            PluginStartup.PluginStartups.ForEach(t => t.PreInitialize(Configuration));
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(CmsModule).GetAssembly());
        }
    }
}
